﻿using System;
using System.Collections;
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Serialization;
using System.Runtime.Serialization;

namespace SimpleLibraryClasses 
{
    [Serializable()]
    public class Member
    {
        private  string _memberId ;
        private string _firstName ;
        private string _lastName ;

        public Member()
        {
            this.Loans = new List<Loan>();
        }

        public Member(string memberId, string firstName, string lastName) : this()
        {

            MemberId = memberId;
            FirstName = firstName;
            LastName = lastName;
        }


        
        /// <summary>
        /// The Display Name for the Member
        /// </summary>
        public String DisplayName
        {
            get
            {
                return LastName + ", " + FirstName;
            }
        }

        /// <summary>
        /// The unique identifier for this member
        /// </summary>
        public String MemberId
        {
            get {return _memberId;}
            set { _memberId = value; }
        }
        /// <summary>
        /// The member's first name
        /// </summary>
        public String FirstName
        {
            get { return _firstName; }
            set { _firstName = value; }
        }

        /// <summary>
        /// The member's last name
        /// </summary>
        public String LastName
        {
            get { return _lastName; }
            set { _lastName = value; }
        }

        /// <summary>
        /// List of all current loans for this member
        /// </summary>
        public List<Loan> Loans { get; private set; }

        /// <summary>
        /// Tests that the member in question satisfies all contraints
        /// </summary>
        /// <returns>True of the member is valid, false otherwise</returns>
        public bool IsValid()
        {
            if (String.IsNullOrEmpty(this.MemberId)) 
            { 
                return false; 
            }
            else 
            { 
                return true; 
            }
        }

        /// <summary>
        /// Add a new loan to this member's account
        /// </summary>
        /// <param name="newLoan">The loan to add</param>
        public void AddLoan(Loan newLoan)
        {
            this.Loans.Add(newLoan);
        }

        /// <summary>
        /// Remove a returned loan to this member's account
        /// </summary>
        /// <param name="oldLoan">The loan to remove</param>
        public void RemoveLoan(Loan oldLoan)
        {
            this.Loans.Remove(oldLoan);
        }
    }

}


